import grp

# 1.通过 组id/gid 获取
id=1000
group_info = grp.getgrgid(id)
print(group_info)
'''grp.struct_group(gr_name='liuj', gr_passwd='x', gr_gid=1000, gr_mem=[])'''

# 2.通过 组名
name="liuj"
group_info = grp.getgrnam(name)
print(group_info)
'''grp.struct_group(gr_name='liuj', gr_passwd='x', gr_gid=1000, gr_mem=[])'''

# 3.获取所有组信息
group_list = grp.getgrall()
print(group_list)
'''
[
grp.struct_group(gr_name='root', gr_passwd='x', gr_gid=0, gr_mem=[]), 
grp.struct_group(gr_name='daemon', gr_passwd='x', gr_gid=1, gr_mem=[]),
]
'''

# 4.获取不存在的组
try:
    group_info = grp.getgrgid(999999999)
except KeyError as e:
    print(e)